<?php
    use yii\helpers\Url;
    use yii\helpers\Html;
    use yii\captcha\Captcha;
    use yii\widgets\ActiveForm;
    use frontend\models\operate\User;
    $this->title = '课程详情';

    //$this->registerJsFile('@web/jwplay/jquery_cookie.js');
    //$this->registerJsFile('@web/jwplay/js/jwplayer.js');

    $session = yii::$app->session;
    $user_id = $session->get('user_id');
    if(!empty($user_id))
    {
      $user = User::find()->select("user_id,user_name,user_thumb")->where("user_id=$user_id")->asarray()->one();
    }
    else
    {
      $user = "";
    }
?>
<style>
  .iPhone-num .ipt{width:100px; float:left;padding:10px;}
</style>

<link href="/static/css/public-same.css" rel="stylesheet">
<link href="/static/css/question.css" rel="stylesheet">

<div class="zy_main">

<div class="container">
<div class="zy_top_nav font14"><a href="http://www.bwphp.com/">首页</a>  &gt;<a href="http://www.bwphp.com/">视频课程</a>  &gt;  <?php echo $course['detail']['course_name']; ?> &gt; <?php echo $move->period_name ?></div>
<div class="course-play">
<dl class="course-lead">
    <dt><?php echo $course['detail']['course_name'] ?><span class="course-lead-state" style="color:#1BBC9B">(<?php if ($course['detail']['is_serialize']==1) { echo "连载中";}else{ echo "已完结";} ?>)</span></dt>
    <dd>课程描述：<?php echo $course['detail']['describe'] ?>&nbsp;&nbsp;&nbsp;&nbsp;<?php if ($course['detail']['type_id']==11) { ?>
      开课地点：<?php echo $course['detail']['open_date'] ?>
    <?php } ?></dd>



</dl>

<script src="/assets/movie/jquery.min.js" type="text/javascript"></script>
<script src="/assets/movie/jwplayer.js" type="text/javascript"></script>
<!--
<div class="course-play-container">
    <div class="row popover-test-container">
        <div style="float:left">
        <div id="course-container" >
        <!--class="col-xs-12 col-sm-12 col-md-8 col-lg-8 course-play-box" style="background-color: #000;float:left"
            <iframe style="width:750px;height:422px;" src="<?= Url::to(['course/play']) ?>" frameborder="0"></iframe>
            -->
            <!--
        </div>
        </div>
        <div style="float:left">
        <input type="hidden" id="movie_url"  value="<?php echo $movie_url ?>">
        <input type="hidden" id="movie_name" value="<?php echo $movie_name ?>">
        <input type="hidden" id="user_id"    value="<?php echo $user_id; ?>">
        <input type="hidden" id="history_time" value="">
        <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 course-play-list" >
            <h1>课程章节</h1>

            <div tabindex="0" id="playlist" class="playlist scroll-pane jspScrollable" style="overflow: hidden; padding: 0px; width: 410px;">

          <iframe style="width:410px; height: 365px;" src="/index.php/course/side?course_id=<?php echo $course['detail']['course_id'] ?>" frameborder="0"></iframe>


            <div style="width: 410px; height: 366px;" class="jspContainer">


            <div class="jspVerticalBar"><div class="jspCap jspCapTop"></div><div style="height: 366px;" class="jspTrack"></div><div class="jspCap jspCapBottom"></div></div></div></div>
        </div>
        </div>
    </div>
    -->
<div style="postion: relative;">
    <div id="course-container" style="width: 750px; height: 422px;" ></div>
    <h3 style="width:410px; background-color:#6699ff;padding:17px 0px 17px 20px; position: absolute; top: 115px;left: 750px;">课程章节</h1>

    <iframe style="width:410px; height: 365px; position: absolute; top: 172px;left: 750px;" src="/index.php/course/side?course_id=<?php echo $course['detail']['course_id'] ?>" frameborder="0"></iframe>
    <div style="clear: both;">
    </div>

</div>
<input type="hidden" id="movie_name" value="<?php echo $movie->movie_name ?>">
<input type="hidden" id="period_id"  value="<?php echo $movie->period_id ?>">
<input type="hidden" id="course_id"  value="<?php echo $movie->course_id ?>">
<input type="hidden" id="user_id"    value="<?php echo $user_id; ?>">
<input type="hidden" id="history_time" value="0">
<script type="text/javascript">jwplayer.key="KVSnE/FWc+VUcBX1hZEJYJ10DI/3yNV5wTPG/w==";</script>
<script type="text/javascript">
	var thePlayer;  //保存当前播放器以便操作
	$(function() {
     var movie_name = $("#movie_name").val();
     var user_id    = $("#user_id").val();
     var period_id  = $("#period_id").val();
     var course_id  = $("#course_id").val();
         play       = 1;
     var num        = movie_name.indexOf('.');
     var type       = movie_name.substr(num+1);

    if (type == "mp4") {
        url = 'rtmp://101.200.211.187/live/mp4:'+movie_name;
      }
      if (type == "flv") {
        url = 'rtmp://101.200.211.187/live/'+movie_name;
      }

		thePlayer = jwplayer('course-container').setup({
			flashplayer: '/assets/movie/jwplayer.flash.swf',
      file: url,
      width: 750,
      height: 422,
      dock: false,
			events: {
                //onComplete: function () { console.log("播放结束!!!"); },
                //播放结束时触发
                onComplete: function () {
                  console.log("播放完成!!!");
                    //thePlayer.seek($.cookie(movie_name,''));
                    //thePlayer.seek(getCookie(movie_name+user_id));
                    $.ajax({
                        url: "<?php echo Url::to(['course/learn-log']);?>",
                        type: 'GET',
                        data: {user_id: user_id,course_id:course_id,period_id:period_id,status:'finished'},
                      });
                },

                onVolume: function () { console.log("声音大小改变!!!"); },
                onReady: function () { console.log("准备就绪!!!");},
                //开始时  读取历史记录
                onPlay: function () {
                        console.log("开始播放!!!");
                        if (play == 1) {
                            thePlayer.seek(getCookie(movie_name+user_id));
                            console.log(getCookie(movie_name+user_id));
                        }
                        delete play;
                        //console.log(getCookie(movie_name+user_id));
                         //thePlayer.seek(getCookie(movie_name+user_id));
                         //thePlayer.seek(o.x);
                         //delete o.x;
                         //console.log(getCookie(movie_name+user_id));

                  },
                //暂停时 记录位置
                onPause: function () {
                          console.log("暂停!!!");
                          play = 1;
                          var movie_name = $("#movie_name").val();
                          setCookie(movie_name+user_id, parseInt(thePlayer.getPosition()));

                    },

                onBufferChange: function () { console.log("缓冲改变!!!"); },
                onBufferFull: function () { console.log("视频缓冲完成!!!"); },
                onError: function (obj) { console.log("播放器出错!!!" + obj.message); },
                onFullscreen: function (obj) { if (obj.fullscreen) { console.log("全屏"); } else { console.log("非全屏"); } },
                onMute: function (obj) { console.log("静音/取消静音") }
            }
        });

      //页面关闭时记录播放位置
    window.onbeforeunload = function(event) {

        var state = thePlayer.getState();
        if (state == 'PLAYING') {
            var movie_name = $("#movie_name").val();
            setCookie(movie_name+user_id,parseInt(thePlayer.getPosition()));
        }
        if (parseInt(thePlayer.getPosition())>parseInt(thePlayer.getDuration())*0.9){
          var status = 'finished';
        }else{
          var status = 'learning';
        }

        $.ajax({
              url: "<?php echo Url::to(['course/learn-log']);?>",
                  type: 'GET',
                  data: {user_id: user_id,course_id:course_id,period_id:period_id,status:status},
              });
        }


	});




    //设置cookie
    function setCookie(c_name,value)
    {
      var expiredays=30;
      var exdate=new Date()
      exdate.setDate(exdate.getDate()+expiredays)
      document.cookie=c_name+ "=" +escape(value)+
      ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
    }
    //取出cookie
    function getCookie(c_name)
    {
    if (document.cookie.length>0)
      {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
          {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
          }
      }
    return ""
    }
</script>


<?= Html::jsFile('/ueditor/ueditor.config.js')?>
<?= Html::jsFile('/ueditor/_examples/editor_api.js')?>


    <div class="row course-play-info visible-md visible-lg">
        <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8 aside-l">
            <ul class="course-play-tabs" role="tablist">
                <li class="active"><a href="#comm" role="tab" data-toggle="tab">用户评论</a></li>
                <li class="visible-md visible-lg"><a href="#question" role="tab" data-toggle="tab">课程问答</a></li>
            </ul>
            <div class="tab-content">

<div class="tab-pane active" id="comm">

      <div id="commentbox" class="media">
      <a href="<?= Url::to(['center/index'])?>" class="pull-left">
        <img src="http://files.bwphp.com/file/image/show/50/50?path=<?= Html::encode($user['user_thumb'])?>" class="media-object">
      </a>
      <div class="media-body">
        <div class="comment-input">
          <?php $form = ActiveForm::begin([
                'action' => ['course/comment'],
                'method'=>'post',
            ])?>
            <textarea class="form-control" name="comment_content" placeholder="发表回答"></textarea><br />
            <div class="comm-reply-foot">
            <?= $form->field($model, 'verifyCode1', [
                    'options' => ['class' => ''],
                ])->widget(Captcha::className(),[
                   'template' => '<p class="iPhone-num">{image}<span class="img-num">{input}</span></p>',
                   'imageOptions' => ['alt' => '验证码'],
                   'captchaAction' => 'course/captcha',
                   'options' =>['placeholder' => '请输入验证码', 'class' => 'ipt'],
                ]); ?>
                <input type="hidden" name="course_id" value="<?= Html::encode($course_id)?>">

              <input id="main-reply" class="btn btn-micv5 btn-lg-fts reply" parent_id="0" value="回答" type="submit">

              &nbsp; &nbsp;<span style="color:red;display:none;">至少3个字</span>


            </div>
            <?php $form = ActiveForm::end()?>

        </div>
      </div>
    </div>

      <div id="comment_list">


    <?php foreach ($course['comment'] as $key => $comment) {?>
    <div class="item">

      <div class="col-left">
        <div class="col-in">
          <div class="u-photo-box">
            <a href="/index.php/center/index" class="pull-left">
              <img style="max-width:none" src="http://files.bwphp.com/file/image/show/50/50?path=<?= Html::encode($user['user_thumb'])?>" class="media-object">
            </a>

            <i class="ico ico-umark-2"></i>

          </div>
        </div>
      </div>
      <div class="col-right">
        <div class="media-body">
        <div class="media-heading">
          <a href="javascript:void(0)" style="float:left"><?= Html::encode($comment['user_name'])?></a>
          <span class="bullet">•</span>
          <span class="text-muted">
            <?php
                        $dur = time()-$comment['comment_addtime'];
                        /*暂时没想到怎么做、先做成这样的*/
                        if($dur<60){
                            echo $dur."秒前";
                        }else{
                            if($dur<3600){
                                echo floor($dur/60)."分钟前";
                            }else{
                                if($dur<86400){
                                    echo floor($dur/3600)."小时前";
                                }else{
                                    if($dur<604800){
                                        echo floor($dur/86400)."天前";
                                    }else{
                                        if($dur<2592000){
                                            echo floor($dur/604800)."周前";
                                        }else{
                                            if($dur<31104000){
                                                echo floor($dur/2592000)."月前";
                                            }else{
                                                if($dur>31104000){
                                                    echo floor($dur/31104000)."年前";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        echo $year;
                    ?>
          </span>
        </div>
        <div class="media-content">
          <div><span class="stars-5"></span></div>
          <?= Html::encode($comment['comment_content'])?>
        </div>
      </div>
      </div>
    </div>
  <?php }?>


      </div>

  </div>

   <div class="tab-pane" id="question">

      <div id="commentbox" class="media">

      <div class="media-body">
        <div class="comment-input input-title ">
          <?php $form = ActiveForm::begin([
                                'options'=>['class'=>'form-horizontal'],
                                'action' => ['course/reply'],
                                'method'=>'post',
                        ])?>
                    <!--标题-->

                    <div class="form-group">
                        <label for="" class="col-sm-1 control-label"><span class="red">*</span>标题</label>
                        <div class="col-sm-11">
                            <input class="form-control" id="form-title" maxlength="40" name="title" placeholder="请给您的问题起个好标题 ..." rows="1" type="text">

                        </div>
                    </div>

                    <!--内容-->
                    <div class="form-group">
                        <label for="" class="col-sm-1 control-label"><span class="red">*</span>内容</label>
                        <div class="col-sm-11">
                        <textarea  id="myEditor"></textarea>

                        </div>
                    </div>

                    <!--标签-->
                    <div class="form-group">
                        <label for="" class="col-sm-1 control-label"><span class="red">*</span>标签</label>
                        <div class="col-sm-11">
                            <div class="add-tag" style=" border: 1px solid #ccc; border-radius: 2px; overflow: hidden;">
                                <div class="hot-tag-box">

                                </div>
                                <input id="inpTags" autocomplete="off" m='<?php
                        $arr = "";
                        foreach ($labels as $key => $label) {
                            $name = $label['queslabel_name'];
                            $label_id = $label['queslabel_id'];
                            $arr[$name]=$label_id;
                        }
                        echo json_encode($arr)?>' class="form-control" placeholder="直接输入可过滤标签，最多打上3个标签" type="text" style="width:611px">
                            </div>

                            <!--输入文字可联想搜索你想用的标签，最多打上3个标签，用空格隔开-->

                        </div>
                    </div>

                    <!--验证码-->
                    <div class="form-group">
                        <label for="" class="col-sm-1 control-label"><span class="red">*</span>验证码</label>
                        <div class="col-sm-11">
                        <div class="comm-reply-foot">
                        <?= $form->field($model, 'verifyCode2', [
                                'options' => ['class' => ''],
                            ])->widget(Captcha::className(),[
                               'template' => '<p class="iPhone-num">{image}<span class="img-num">{input}</span></p>',
                               'imageOptions' => ['alt' => '验证码'],
                               'captchaAction' => 'course/captcha',
                               'options' =>['placeholder' => '请输入验证码', 'class' => 'ipt'],
                            ]); ?>




                        </div>


                        </div>
                    </div>
                    <input type="hidden" name="course_id" value="<?= Html::encode($course_id)?>">
                    <div class="form-group">

                        <div class="col-sm-offset-1 col-sm-11">
                            <button type="submit" class="btn">发布问题</button>
                        </div>

                    </div>
                <?php $form = ActiveForm::end()?>

        </div>
      </div>
    </div>
<div class="ibox-body">
    <div class="QA-list">
     <!--  开始 -->
     <?php
      if(empty($data)){
            echo "抱歉！内容暂时不存在";
        }
       foreach($data as $key=>$val){?>
     <div class="item">
            <div class="col-left">
                <div class="col-in">
                    <div class="u-photo-box">

                        <img src="http://files.bwphp.com/file/image/show/50/50?path=<?= Html::encode($val['user_thumb'])?>" alt="" height="50" width="50">
                        <i class="ico ico-umark-2"></i>

                    </div>
                    <span class="u-name"><?= Html::encode($val['user_name']);?></span>

                </div>
            </div>
            <div class="col-right">
                <div class="col-in item-r-main">
                    <h3>
                        <a href="<?= Url::to(['questions/details'])?>?ques_id=<?php echo $val['ques_id']?>" target="_blank">

                           <?= Html::encode($val['ques_name'])?>                        </a>
                    </h3>
                    <div class="item-r-A">
                        <?php if(!empty($val['answers']['answer_content'])){?>
                        <span class="tips">[最新答案]</span>
                        <a href="<?= Url::to(['questions/details'])?>?ques_id=<?php echo $val['ques_id']?>">
                        <?php echo $val['answers']['answer_content'];?> </a>
                       <?php }else{?>
                       <span class="tips"></span>
                        <a href=""></a>
                       <?php }?>
                    </div>
                    <div class="hot-tag-group">

                        <a href="javascript:void(0);" class="hot-tag"><?= Html::encode($val['queslabel_name'])?></a>
                    </div>
                    <div class="item-r-foot ask-item-r-foot">
                        <div class="col-left" style="width: 26% !important;">

                            <span class="datetime">
                              <?php
                        $dur = time()-$val['ques_addtime'];
                        /*暂时没想到怎么做、先做成这样的*/
                        if($dur<60){
                            echo $dur."秒前";
                        }else{
                            if($dur<3600){
                                echo floor($dur/60)."分钟前";
                            }else{
                                if($dur<86400){
                                    echo floor($dur/3600)."小时前";
                                }else{
                                    if($dur<604800){
                                        echo floor($dur/86400)."天前";
                                    }else{
                                        if($dur<2592000){
                                            echo floor($dur/604800)."周前";
                                        }else{
                                            if($dur<31104000){
                                                echo floor($dur/2592000)."月前";
                                            }else{
                                                if($dur>31104000){
                                                    echo floor($dur/31104000)."年前";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        echo $year;
                    ?>
                            </span>

                        </div>

                                        <a href="">来源:<?= Html::encode($val['course_name'])?></a>
                                            <div class="col-right">
                            <span class="i-item">
                                <a href="javascript:void(0);" target="_blank">回答(<?= Html::encode($val['ques_answersum'])?>)</a>
                            </span>
                            <span class="i-item">
                                <a href="javascript:void(0);" target="_blank">浏览(<?= Html::encode($val['ques_viewsum'])?>)</a>
                            </span>

                        </div>
                    </div>
                </div>
            </div>
        </div>
     <!-- 结束 -->
     <?php }?>
    </div>
    </div>
  </div>
            </div>
        </div>
        <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 aside-r">
                        <div class="v5-box">
  <h1>讲师介绍</h1>
  <div class="media teacher">
    <a class="pull-left hascourse" href="/group/common/dynmsg/5/">
      <img src="<?php echo 'http://files.bwphp.com/file/image/show/100/100?path='.$course['detail']['teacher']['teacher_thumb']; ?>" alt="android开发工程师 sundy">
    </a>
    <div class="media-body">
      <h4 class="media-heading"><a href="/group/common/dynmsg/5/"><?= Html::encode($course['detail']['teacher']['teacher_name']) ?></a></h4>
      <p><?= Html::encode($course['detail']['teacher']['teacher_from'])?></p>
      <a href="/index.php/teacher/teacherinfo?teacher_id=<?php echo $course['detail']['teacher_id'] ?>" class="btn btn-micv5">查看他的课程</a>
    </div>
  </div>
  <article>
      <?= Html::encode($course['detail']['teacher']['teacher_desc'])?>
  </article>
</div>
            <div class="v5-box">
<div id="related-article" data-url="">
<h1>相关文章</h1>
</div>

</div>

        </div>
    </div>


</div>
</div>
</div>
</div>
<script type="text/javascript">
    /*编辑器*/
    var ue = UE.getEditor('myEditor');

    /*标签选择*/
    var input_tags=[];

    var prefetched_tags =$.parseJSON($("#inpTags").attr("m"));

</script>
<script type="text/javascript" src="/static/js/release.js"></script>
